package com.xiaozhen.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaozhen.common.core.domain.app.OauthClientDetails;
import com.xiaozhen.app.dao.OauthClientDetailsDao;
import com.xiaozhen.app.service.SysAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;

/**
 * HISTORY
 *
 * @author zhenweisheng
 * @date 2021/9/24 16:09
 * @description:
 */
@Service
public class SysAuthServiceImpl implements SysAuthService {

    @Autowired
    private OauthClientDetailsDao oauthClientDetailsDao;

    @Override
    public Page<OauthClientDetails> selectClientList(Page<OauthClientDetails> page) {
        QueryWrapper<OauthClientDetails> queryWrapper = new QueryWrapper<>();
        Page<OauthClientDetails> list = oauthClientDetailsDao.selectPage(page, queryWrapper);
        return list;
    }

    @Override
    public Boolean checkClientIdUnique(OauthClientDetails sysAuth) {
        QueryWrapper<OauthClientDetails> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("client_id", sysAuth.getClientId());
        Integer count = oauthClientDetailsDao.selectCount(queryWrapper);
        if (count > 0) {
            return false;
        }
        return true;
    }

    @Override
    public Integer insertSysAuth(OauthClientDetails sysAuth) {
        return oauthClientDetailsDao.insert(sysAuth);
    }

    @Override
    public Integer updateSysAuth(OauthClientDetails sysAuth) {
        return oauthClientDetailsDao.updateById(sysAuth);
    }

    @Override
    public Integer deleteSysAuthByIds(Long[] clientIds) {
        return oauthClientDetailsDao.deleteBatchIds(Arrays.asList(clientIds));
    }
}
